package site.kitcheng.springboottest.test;

import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * ClassName: TaskThread
 * Package: site.kitcheng.springboottest.test
 * Description:
 *
 * @Author jiangCheng
 * @Create 2025/2/10 11:20
 * @Version 1.0
 */
public class TaskThread {

    public static void main(String[] args) throws InterruptedException {
        int  sheetNum = 10;

        long l = System.currentTimeMillis();
        //异步查询和导出
        ExecutorService executorService = Executors.newFixedThreadPool(5); // 可调节线程池大小
        List<Callable<Void>> tasks = new ArrayList<>();

        //开始分批查询分次写入
        for (int i = 0; i < sheetNum; i++) {
            tasks.add(() -> {

                Thread.sleep(1000);

                System.out.println("123");
              return null;
            });

        }

        // 执行异步任务
        executorService.invokeAll(tasks);


        System.out.println("耗时：" + (System.currentTimeMillis() - l));
        // 所有任务完成后关闭线程池
        executorService.shutdown(); // 线程池关闭，防止程序继续运行
    }
}
